<?php
namespace App\Console;

use EasySwoole\Console\ModuleInterface;
use EasySwoole\Socket\Bean\Caller;
use EasySwoole\Socket\Bean\Response;

class TestConsole implements ModuleInterface {

    public function exec(Caller $caller, Response $response) {
        $args = $caller->getArgs();
        $actionName = array_shift($args);
        $caller->setArgs($args);
        switch ($actionName) {
            case 'echo':
                $this->echo($caller, $response);
                break;
            default :
                $this->help($caller, $response);
        }
    }

    public function help(Caller $caller, Response $response) {
        $help = <<<HELP
测试控制器
用法: 命令 [命令参数]
test echo [string] | 输出字符串,测试方法
HELP;
        $response->setMessage($help);
    }

    public function moduleName(): string {
        return 'test';
    }

    private function echo(Caller $caller, Response $response) {
        $msg = array_shift($caller->getArgs());
        $response->setMessage($msg);
    }
}
